package com.mall.quartz.task;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mall.business.domain.TCouponUser;
import com.mall.business.domain.TOrder;
import com.mall.business.domain.TPink;
import com.mall.business.service.ITCouponUserService;
import com.mall.business.service.ITOrderPjService;
import com.mall.business.service.ITOrderService;
import com.mall.business.service.ITPinkService;
import com.mall.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import com.mall.common.utils.StringUtils;

import java.util.Arrays;
import java.util.Date;
import java.util.List;

/**
 * 定时任务调度测试
 *
 * @author ruoyi
 */
@Component("ryTask")
public class RyTask
{

    @Autowired
    private ITPinkService tPinkService;


    @Autowired
    private ITCouponUserService tCouponUserService;



    @Autowired
    private ITOrderService  orderService;

    public void ryMultipleParams(String s, Boolean b, Long l, Double d, Integer i)
    {
        System.out.println(StringUtils.format("执行多参方法： 字符串类型{}，布尔类型{}，长整型{}，浮点型{}，整形{}", s, b, l, d, i));
    }

    public void ryParams(String params)
    {
        System.out.println("执行有参方法：" + params);
    }



    /**
    * @Author:zhaoyongke
    * @Description:拼团过期
    * @param
    * @Date: 2025/4/28 15:18
    */
    public void pinkGq()
    {
        QueryWrapper<TPink> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", "1");
        // 过期的
        queryWrapper.le("end_time", DateUtils.getNowDate());
        List<TPink> pinkList = tPinkService.list(queryWrapper);
        for (int i = 0; i < pinkList.size(); i++) {
            TPink tPink = pinkList.get(i);
            tPink.setStatus("3");
            tPinkService.updateById(tPink);
         }
    }


    /**
     * @Author:zhaoyongke
     * @Description:优惠券过期
     * @param
     * @Date: 2025/4/28 15:18
     */
    public void couponUserGq()
    {
        QueryWrapper<TCouponUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("status", "0");
        // 过期的
        queryWrapper.le("end_date", DateUtils.getNowDate());
        List<TCouponUser> couponUserList = tCouponUserService.list(queryWrapper);
        for (int i = 0; i < couponUserList.size(); i++) {
            TCouponUser couponUser= couponUserList.get(i);
            couponUser.setStatus("2");
            tCouponUserService.updateById(couponUser);
        }
    }




    /**
     * @Author:zhaoyongke
     * @Description:  订单过期
     * @param
     * @Date: 2025/4/28 15:18
     */
    public void orderGq()
    {
        QueryWrapper<TOrder> queryWrapper = new QueryWrapper<>();
        queryWrapper.in("order_status", "1");
        // 超过半小时未支付的 根据订单时间判断
        // 计算半小时前的时间
        Date halfHourAgo = DateUtils.addMinutes(DateUtils.getNowDate(), -30);
        queryWrapper.le("order_time", halfHourAgo);
        List<TOrder> orderList = orderService.list(queryWrapper);
        for (int i = 0; i < orderList.size(); i++) {
            TOrder order= orderList.get(i);
            order.setOrderStatus("6");
            order.setCloseType("1");
            order.setCancelTime(DateUtils.getNowDate());
            orderService.updateById(order);
        }
    }
}
